package com.foo.cms.service.impl;

import com.foo.cms.service.BaseService;
import com.foo.cms.service.SetParamService;
import com.foo.cms.vo.SetParam;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: LZS
 * Date: 12-6-30
 * Time: 下午4:36
 * To change this template use File | Settings | File Templates.
 */
@Service
public class SetParamServiceImpl extends BaseService implements SetParamService {
    @Override
    public SetParam getParamByKey(String key) {
        Map<String,Object> params = new HashMap<String, Object>();
        String sql = "select * from DT_SETPARAM where vc2paramkey=:key";
        params.put("key",key);
        return jdbcTemplate.queryForObject(sql, params,new ParamRowMapper());
    }
}

class ParamRowMapper implements RowMapper<SetParam>{
    @Override
    public SetParam mapRow(ResultSet rs, int rowNum) throws SQLException {
        SetParam param = new SetParam();
        param.setId(rs.getString("numsetid"));
        param.setKey(rs.getString("vc2paramkey"));
        param.setName(rs.getString("vc2paramname"));
        param.setValue(rs.getString("vc2paramvalue"));
        return param;
    }
}


